```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解ReentrantLock</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .code-block {
            background-color: #1e293b;
            border-left: 4px solid #7c3aed;
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            bottom: 2px;
            left: 0;
            width: 100%;
            height: 8px;
            background-color: rgba(124, 58, 237, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover::after {
            height: 14px;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto text-center">
            <div class="inline-block bg-white bg-opacity-20 rounded-full px-4 py-1 mb-4">
                <span class="text-sm font-medium">Java并发编程</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">深入理解<span class="highlight">ReentrantLock</span></h1>
            <p class="text-xl text-white text-opacity-90 max-w-2xl mx-auto">
                Java中强大的可重入互斥锁，提供比synchronized更丰富的功能和更灵活的控制
            </p>
            <div class="mt-8 flex justify-center space-x-4">
                <div class="flex items-center">
                    <i class="fas fa-lock-open text-white mr-2"></i>
                    <span>可重入锁</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-bolt text-white mr-2"></i>
                    <span>高性能</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-sliders-h text-white mr-2"></i>
                    <span>灵活控制</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="max-w-4xl mx-auto px-6 py-12">
        <!-- Overview Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <h2 class="text-2xl font-bold mb-4 text-indigo-600 font-serif">概述</h2>
                <p class="mb-4">
                    <span class="font-semibold">ReentrantLock</span> 是 Java 中一种可重入的互斥锁，比 <span class="font-semibold">synchronized</span> 关键字提供了更丰富的功能和更灵活的控制。它主要用于在多线程编程中控制对共享资源的访问。
                </p>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mt-6">
                    <div class="bg-indigo-50 rounded-lg p-6">
                        <h3 class="text-lg font-semibold mb-2 text-indigo-700 flex items-center">
                            <i class="fas fa-check-circle mr-2"></i>优势
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                                <span>可重入特性 - 同一线程可多次获取锁</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                                <span>支持公平锁与非公平锁</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                                <span>尝试获取锁(tryLock)机制</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                                <span>支持可中断的锁获取</span>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-indigo-50 rounded-lg p-6">
                        <h3 class="text-lg font-semibold mb-2 text-indigo-700 flex items-center">
                            <i class="fas fa-exclamation-triangle mr-2"></i>注意事项
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                                <span>必须显式调用lock()和unlock()</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                                <span>unlock()应在finally块中调用</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                                <span>避免锁的过度使用导致性能问题</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                                <span>注意死锁风险</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- 1. Basic Usage -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">1</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">基本使用方式</h2>
                </div>
                <p class="mb-4">
                    <span class="font-semibold">ReentrantLock</span> 最基本的使用方式类似于 <span class="font-semibold">synchronized</span>，但其更加灵活。使用时，需要显式地调用 <span class="font-semibold">lock()</span> 和 <span class="font-semibold">unlock()</span> 方法来加锁和释放锁。
                </p>
                <div class="code-block rounded-lg my-6 overflow-hidden">
                    <pre class="text-gray-200 p-4 overflow-x-auto">
                        <code class="language-java">
ReentrantLock lock = new ReentrantLock();

try {
    lock.lock();
    // 保护的代码块
} finally {
    lock.unlock();
}
                        </code>
                    </pre>
                </div>
                <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 my-6">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-exclamation-circle text-yellow-500"></i>
                        </div>
                        <div class="ml-3">
                            <h3 class="text-sm font-medium text-yellow-800">注意事项</h3>
                            <div class="mt-2 text-sm text-yellow-700">
                                <ul class="list-disc pl-5 space-y-1">
                                    <li><span class="font-medium">lock()</span> 和 <span class="font-medium">unlock()</span> 必须成对出现</li>
                                    <li>最好在 <span class="font-medium">finally</span> 块中调用 <span class="font-medium">unlock()</span> 以确保即使发生异常也能正确释放锁</li>
                                    <li><span class="font-medium">ReentrantLock</span> 是可重入的，同一个线程可以多次获取锁</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 2. Fair vs Unfair Lock -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">2</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">公平锁与非公平锁</h2>
                </div>
                <p class="mb-4">
                    <span class="font-semibold">ReentrantLock</span> 可以配置为公平锁或非公平锁。默认情况下，它是非公平锁。这两种锁的选择取决于业务需求：
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 my-6">
                    <div class="feature-card bg-white border border-gray-200 rounded-lg p-6 transition-all duration-300 shadow-sm hover:shadow-md">
                        <div class="flex items-center mb-3">
                            <div class="bg-red-100 p-2 rounded-full mr-3">
                                <i class="fas fa-random text-red-500"></i>
                            </div>
                            <h3 class="text-lg font-semibold">非公平锁 (默认)</h3>
                        </div>
                        <p class="text-gray-600">
                            非公平锁在锁释放时，任何线程都有机会去抢占锁，不管它是否在等待队列中，可能导致"插队"现象，提升吞吐量。
                        </p>
                    </div>
                    <div class="feature-card bg-white border border-gray-200 rounded-lg p-6 transition-all duration-300 shadow-sm hover:shadow-md">
                        <div class="flex items-center mb-3">
                            <div class="bg-green-100 p-2 rounded-full mr-3">
                                <i class="fas fa-equals text-green-500"></i>
                            </div>
                            <h3 class="text-lg font-semibold">公平锁</h3>
                        </div>
                        <p class="text-gray-600">
                            公平锁确保线程按照请求锁的顺序来获取锁，避免线程饥饿，但可能会降低整体吞吐量。
                        </p>
                    </div>
                </div>
                
                <div class="code-block rounded-lg my-6 overflow-hidden">
                    <pre class="text-gray-200 p-4 overflow-x-auto">
                        <code class="language-java">
// 创建公平锁
ReentrantLock lock = new ReentrantLock(true);
                        </code>
                    </pre>
                </div>
                
                <div class="bg-blue-50 border-l-4 border-blue-400 p-4 my-6">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-blue-500"></i>
                        </div>
                        <div class="ml-3">
                            <h3 class="text-sm font-medium text-blue-800">选择建议</h3>
                            <div class="mt-2 text-sm text-blue-700">
                                <p>在大多数情况下，非公平锁的性能优于公平锁，因为减少了线程切换的开销。只有在需要保证绝对公平性的场景下才使用公平锁。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 3. Try Locking -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">3</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">尝试获取锁 (Try Locking)</h2>
                </div>
                <p class="mb-4">
                    <span class="font-semibold">ReentrantLock</span> 提供了 <span class="font-semibold">tryLock()</span> 方法，可以尝试在指定时间内获取锁，而不是无限等待。这在防止死锁、提高系统响应性方面非常有用。
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 my-6">
                    <div class="code-block rounded-lg overflow-hidden">
                        <pre class="text-gray-200 p-4 overflow-x-auto">
                            <code class="language-java">
// 立即尝试获取锁
if (lock.tryLock()) {
    try {
        // 保护的代码块
    } finally {
        lock.unlock();
    }
} else {
    // 处理未能获取锁的情况
}
                            </code>
                        </pre>
                    </div>
                    <div class="code-block rounded-lg overflow-hidden">
                        <pre class="text-gray-200 p-4 overflow-x-auto">
                            <code class="language-java">
// 带超时的尝试获取锁
if (lock.tryLock(10, TimeUnit.SECONDS)) {
    try {
        // 保护的代码块
    } finally {
        lock.unlock();
    }
} else {
    // 处理未能获取锁的情况
}
                            </code>
                        </pre>
                    </div>
                </div>
                
                <div class="bg-indigo-50 rounded-lg p-6 mt-6">
                    <h3 class="text-lg font-semibold mb-3 text-indigo-700 flex items-center">
                        <i class="fas fa-question-circle mr-2"></i>使用场景
                    </h3>
                    <ul class="space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>需要避免死锁的场景</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>对响应时间有严格要求的系统</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chevron-right text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>需要实现超时控制的业务逻辑</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- 4. Interruptible Locking -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">4</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">可中断锁 (Interruptible Locking)</h2>
                </div>
                <p class="mb-4">
                    <span class="font-semibold">ReentrantLock</span> 提供 <span class="font-semibold">lockInterruptibly()</span> 方法，允许线程在等待锁时响应中断。这对于实现可取消的任务特别有用。
                </p>
                
                <div class="code-block rounded-lg my-6 overflow-hidden">
                    <pre class="text-gray-200 p-4 overflow-x-auto">
                        <code class="language-java">
try {
    lock.lockInterruptibly();
    // 保护的代码块
} catch (InterruptedException e) {
    // 处理中断
} finally {
    if (lock.isHeldByCurrentThread()) {
        lock.unlock();
    }
}
                        </code>
                    </pre>
                </div>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mt-6">
                    <div class="bg-purple-50 rounded-lg p-6">
                        <h3 class="text-lg font-semibold mb-2 text-purple-700 flex items-center">
                            <i class="fas fa-check-circle mr-2"></i>优点
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-purple-500 mt-1 mr-2 text-xs"></i>
                                <span>提高系统响应性</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-purple-500 mt-1 mr-2 text-xs"></i>
                                <span>避免线程长时间等待</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-purple-500 mt-1 mr-2 text-xs"></i>
                                <span>更好的资源管理</span>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-purple-50 rounded-lg p-6">
                        <h3 class="text-lg font-semibold mb-2 text-purple-700 flex items-center">
                            <i class="fas fa-exclamation-circle mr-2"></i>注意事项
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-purple-500 mt-1 mr-2 text-xs"></i>
                                <span>需要正确处理InterruptedException</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-purple-500 mt-1 mr-2 text-xs"></i>
                                <span>确保锁最终被释放</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-chevron-right text-purple-500 mt-1 mr-2 text-xs"></i>
                                <span>检查当前线程是否持有锁再释放</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- 5. Condition Variables -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">5</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">条件变量 (Condition Variables)</h2>
                </div>
                <p class="mb-4">
                    <span class="font-semibold">ReentrantLock</span> 支持多个 <span class="font-semibold">Condition</span> 对象，类似于 <span class="font-semibold">Object</span> 的 <span class="font-semibold">wait()</span> 和 <span class="font-semibold">notify()</span>。条件变量用于线程间协调，使得线程可以在特定条件下等待或唤醒。
                </p>
                
                <div class="code-block rounded-lg my-6 overflow-hidden">
                    <pre class="text-gray-200 p-4 overflow-x-auto">
                        <code class="language-java">
ReentrantLock lock = new ReentrantLock();
Condition condition = lock.newCondition();

lock.lock();
try {
    while (/* condition not met */) {
        condition.await();
    }
    // 处理业务逻辑
    condition.signalAll(); // 唤醒等待线程
} finally {
    lock.unlock();
}
                        </code>
                    </pre>
                </div>
                
                <div class="bg-pink-50 border-l-4 border-pink-400 p-4 my-6">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-info-circle text-pink-500"></i>
                        </div>
                        <div class="ml-3">
                            <h3 class="text-sm font-medium text-pink-800">应用场景</h3>
                            <div class="mt-2 text-sm text-pink-700">
                                <p>这种机制特别适合实现复杂的线程间协作，比如生产者-消费者模型、读写锁、屏障等并发模式。</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Mermaid Diagram -->
                <div class="mt-8">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">生产者-消费者模型示例</h3>
                    <div class="mermaid">
                        graph TD
                            A[生产者线程] -->|put| B[缓冲区]
                            B -->|take| C[消费者线程]
                            D[Condition notFull] -->|await| A
                            B -->|signal| D
                            E[Condition notEmpty] -->|await| C
                            B -->|signal| E
                    </div>
                </div>
            </div>
        </section>

        <!-- 6. Lock Timeout & Deadlock Detection -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">6</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">锁超时与死锁检测</h2>
                </div>
                <p class="mb-4">
                    在某些情况下，锁的获取可能会导致死锁。为此，可以使用 <span class="font-semibold">tryLock()</span> 结合超时机制来避免死锁问题。这种策略适用于对锁获取时间敏感的场景。
                </p>
                
                <div class="code-block rounded-lg my-6 overflow-hidden">
                    <pre class="text-gray-200 p-4 overflow-x-auto">
                        <code class="language-java">
if (lock.tryLock(2, TimeUnit.SECONDS)) {
    try {
        // 处理业务逻辑
    } finally {
        lock.unlock();
    }
} else {
    // 处理锁获取失败的情况
    // 可能是死锁或系统过载
}
                        </code>
                    </pre>
                </div>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mt-6">
                    <div>
                        <h3 class="text-lg font-semibold mb-3 text-gray-800">死锁检测策略</h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <span class="bg-red-100 text-red-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded">关键</span>
                                <span>设置合理的超时时间</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-blue-100 text-blue-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded">建议</span>
                                <span>按照固定顺序获取多个锁</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-green-100 text-green-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded">最佳实践</span>
                                <span>使用工具检测潜在死锁</span>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h3 class="text-lg font-semibold mb-3 text-gray-800">处理锁获取失败</h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-sync-alt text-gray-500 mt-1 mr-2 text-xs"></i>
                                <span>重试机制 (带退避策略)</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-exclamation-triangle text-gray-500 mt-1 mr-2 text-xs"></i>
                                <span>记录日志并告警</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-undo text-gray-500 mt-1 mr-2 text-xs"></i>
                                <span>回滚已执行的操作</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- 7. Lock Downgrading -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">7</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">锁降级 (Lock Downgrading)</h2>
                </div>
                <p class="mb-4">
                    锁降级是指在持有写锁的情况下，降级为读锁的过程。<span class="font-semibold">ReentrantLock</span> 本身不直接支持读写锁，但通过结合 <span class="font-semibold">ReentrantReadWriteLock</span>，可以实现锁的降级。
                </p>
                
                <div class="code-block rounded-lg my-6 overflow-hidden">
                    <pre class="text-gray-200 p-4 overflow-x-auto">
                        <code class="language-java">
ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
rwLock.writeLock().lock();

try {
    // 写操作
    rwLock.readLock().lock();
} finally {
    rwLock.writeLock().unlock(); // 降级为读锁
}

try {
    // 读操作
} finally {
    rwLock.readLock().unlock();
}
                        </code>
                    </pre>
                </div>
                
                <div class="bg-green-50 border-l-4 border-green-400 p-4 my-6">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-chart-line text-green-500"></i>
                        </div>
                        <div class="ml-3">
                            <h3 class="text-sm font-medium text-green-800">性能优势</h3>
                            <div class="mt-2 text-sm text-green-700">
                                <p>锁降级可以提高系统的并发性能，允许更多线程并行访问共享资源，同时保证数据的一致性。这在读多写少的场景中特别有用。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 8. Performance & Scalability -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">8</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">性能与可扩展性</h2>
                </div>
                <p class="mb-4">
                    <span class="font-semibold">ReentrantLock</span> 相比 <span class="font-semibold">synchronized</span> 具有更好的性能和可扩展性。在高并发场景中，<span class="font-semibold">ReentrantLock</span> 的锁争用和调度机制更加优化，特别是在配置为非公平锁时，它能够显著提高系统的吞吐量。
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 my-6">
                    <div class="bg-gray-50 rounded-lg p-6">
                        <h3 class="text-lg font-semibold mb-3 text-gray-800">性能对比</h3>
                        <ul class="space-y-3">
                            <li>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium">ReentrantLock (非公平)</span>
                                    <span class="text-sm font-medium">90%</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div class="bg-indigo-600 h-2.5 rounded-full" style="width: 90%"></div>
                                </div>
                            </li>
                            <li>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium">ReentrantLock (公平)</span>
                                    <span class="text-sm font-medium">70%</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div class="bg-indigo-500 h-2.5 rounded-full" style="width: 70%"></div>
                                </div>
                            </li>
                            <li>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium">synchronized</span>
                                    <span class="text-sm font-medium">65%</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div class="bg-indigo-400 h-2.5 rounded-full" style="width: 65%"></div>
                                </div>
                            </li>
                        </ul>
                        <p class="text-xs text-gray-500 mt-2">* 基于典型高并发场景下的吞吐量比较</p>
                    </div>
                    <div>
                        <h3 class="text-lg font-semibold mb-3 text-gray-800">功能对比</h3>
                        <div class="overflow-x-auto">
                            <table class="w-full text-sm text-left text-gray-500">
                                <thead class="text-xs text-gray-700 uppercase bg-gray-50">
                                    <tr>
                                        <th scope="col" class="px-4 py-3">特性</th>
                                        <th scope="col" class="px-4 py-3">ReentrantLock</th>
                                        <th scope="col" class="px-4 py-3">synchronized</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr class="bg-white border-b">
                                        <td class="px-4 py-2 font-medium">可重入</td>
                                        <td class="px-4 py-2"><i class="fas fa-check text-green-500"></i></td>
                                        <td class="px-4 py-2"><i class="fas fa-check text-green-500"></i></td>
                                    </tr>
                                    <tr class="bg-white border-b">
                                        <td class="px-4 py-2 font-medium">公平锁</td>
                                        <td class="px-4 py-2"><i class="fas fa-check text-green-500"></i></td>
                                        <td class="px-4 py-2"><i class="fas fa-times text-red-500"></i></td>
                                    </tr>
                                    <tr class="bg-white border-b">
                                        <td class="px-4 py-2 font-medium">尝试获取锁</td>
                                        <td class="px-4 py-2"><i class="fas fa-check text-green-500"></i></td>
                                        <td class="px-4 py-2"><i class="fas fa-times text-red-500"></i></td>
                                    </tr>
                                    <tr class="bg-white border-b">
                                        <td class="px-4 py-2 font-medium">可中断</td>
                                        <td class="px-4 py-2"><i class="fas fa-check text-green-500"></i></td>
                                        <td class="px-4 py-2"><i class="fas fa-times text-red-500"></i></td>
                                    </tr>
                                    <tr class="bg-white">
                                        <td class="px-4 py-2 font-medium">条件变量</td>
                                        <td class="px-4 py-2"><i class="fas fa-check text-green-500"></i></td>
                                        <td class="px-4 py-2"><i class="fas fa-times text-red-500"></i></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 9. Practical Choices -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="flex items-center mb-4">
                    <span class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">9</span>
                    <h2 class="text-2xl font-bold text-indigo-600 font-serif">实际应用中的选择</h2>
                </div>
                <p class="mb-4">
                    在实际开发中，选择 <span class="font-semibold">ReentrantLock</span> 还是 <span class="font-semibold">synchronized</span> 取决于具体场景：
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 my-6">
                    <div class="bg-blue-50 rounded-lg p-6">
                        <h3 class="text-lg font-semibold mb-3 text-blue-700 flex items-center">
                            <i class="fas fa-lock mr-2"></i>使用 synchronized
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>简单的同步场景</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>锁竞争不激烈</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>代码简洁性优先</span>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-purple-50 rounded-lg p-6">
                        <h3 class="text-lg font-semibold mb-3 text-purple-700 flex items-center">
                            <i class="fas fa-lock-open mr-2"></i>使用 ReentrantLock
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>需要精细控制锁的获取与释放</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>实现复杂的线程间协调</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>需要高级特性(公平锁、可中断等)</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <!-- Mermaid Flowchart -->
                <div class="mt-8">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">选择决策流程图</h3>
                    <div class="mermaid">
                        graph TD
                            A[需要线程同步] --> B{简单同步?}
                            B -->|是| C[使用synchronized]
                            B -->|否| D{需要以下特性?<br/>- 公平锁<br/>- 可中断<br/>- 尝试获取锁<br/>- 多条件变量}
                            D -->|是| E[使用ReentrantLock]
                            D -->|否| C
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="bg-indigo-50 rounded-xl p-8">
            <h2 class="text-2xl font-bold text-indigo-700 mb-6 text-center font-serif">ReentrantLock关键知识点总结</h2>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="bg-white rounded-lg p-6 shadow-sm">
                    <div class="text-indigo-600 text-2xl mb-3">
                        <i class="fas fa-key"></i>
                    </div>
                    <h3 class="text-lg font-semibold mb-2">核心特性</h3>
                    <ul class="space-y-1 text-sm">
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>可重入互斥锁</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>支持公平/非公平锁</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>可中断锁获取</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white rounded-lg p-6 shadow-sm">
                    <div class="text-indigo-600 text-2xl mb-3">
                        <i class="fas fa-cogs"></i>
                    </div>
                    <h3 class="text-lg font-semibold mb-2">高级功能</h3>
                    <ul class="space-y-1 text-sm">
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>尝试获取锁(tryLock)</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>多个条件变量(Condition)</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>锁降级支持</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white rounded-lg p-6 shadow-sm">
                    <div class="text-indigo-600 text-2xl mb-3">
                        <i class="fas fa-lightbulb"></i>
                    </div>
                    <h3 class="text-lg font-semibold mb-2">最佳实践</h3>
                    <ul class="space-y-1 text-sm">
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>unlock()放在finally块</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>合理使用tryLock避免死锁</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-2 text-xs"></i>
                            <span>根据场景选择公平/非公平锁</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 微交互效果
        document.querySelectorAll('.feature-card').forEach(card => {
            card.addEventListener('mouseenter', () => {
                card.style.transform = 'translateY(-5px)';
            });
            card.addEventListener('mouseleave', () => {
                card.style.transform = '';
            });
        });
        
        document.querySelectorAll('.highlight').forEach(el => {
            el.addEventListener('mouseenter', function() {
                this.querySelector('span').style.color = '#7c3aed';
            });
            el.addEventListener('mouseleave', function() {
                this.querySelector('span').style.color = '';
            });
        });
    </script>
</body>
</html>
```